package com.example.log.alarm.agent;

import com.example.log.alarm.constant.InterceptorType;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: spring-agent
 * @description:
 * @author: zt22328 赵儒定
 * @create: 2023-03-31 15:08
 **/
@Data
@NoArgsConstructor
public class AgentVisitBase {

    /**
     * 类
     */
    protected String className;

    /**
     * 拦截对象
     */
    protected Class<?> adviceInterceptor;

    /**
     *
     */
    protected List<MethodDefinition> methods = new ArrayList<>();

    /**
     * 是否构造器
     */
    protected InterceptorType interceptorType;

    public AgentVisitBase(String className, Class<?> adviceInterceptor) {
        this.className = className;
        this.adviceInterceptor = adviceInterceptor;
    }

    public AgentVisitBase(String className, Class<?> adviceInterceptor, InterceptorType interceptorType) {
        this.className = className;
        this.adviceInterceptor = adviceInterceptor;
        this.interceptorType = interceptorType;
    }

    public void addMethodDefinition(MethodDefinition ... definitions) {
        this.methods.addAll(Arrays.asList(definitions));
    }

    @Data
    @NoArgsConstructor
    public static class MethodDefinition {


        private String name;

        private List<String> paramTypes;

        private boolean allMethods;

        public MethodDefinition(String name, String ... paramTypes) {
            this.name = name;
            this.paramTypes = Arrays.asList(paramTypes);
        }

    }
}
